#ifndef GLOBAL
#define GLOBAL

/*
#include "/home/ysy/QT/VDMA.c"
#include "/home/ysy/QT/xcvt_resize.c"
#include "/home/ysy/QT/xcvt_resize_linux.c"
#include "/home/ysy/QT/interpret_output.cpp"
*/

#include "/home/ysy/QT/xcvt_resize.h"
#include "/home/ysy/QT/xcvt_resize_hw.h"

#include "/home/ysy/QT/interpret_output.h"
#include <opencv2/opencv.hpp>
// RTSP related
#include <stdio.h>
#include <memory.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <iostream>
#include <unistd.h>
// RTSP end
#include "/home/ysy/QT/VDMA.h"

using namespace std;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include <asm-generic/types.h>
#include <linux/videodev2.h>

#include <opencv2/opencv.hpp>

#include <QImage>



#define CAMERA_DEVICE "/dev/video0"

#define VIDEO_WIDTH 640
#define VIDEO_HEIGHT 480
#define VIDEO_FORMAT V4L2_PIX_FMT_YUYV
#define BUFFER_COUNT 4
#define VDMA_READ 1
#define VDMA_WRITE 0

#define lOCK_READY 0
#define lOCK_DONE 1

#define output_length 25088//24500
#define USE_CAMERA 0
#define TEST_IMG_NUM 15
#define RTSP 1
#define RTSP_ADDRESS "rtsp://admin:y1997212@172.16.6.42/Streaming/Channels/1?tcp"

typedef struct VideoControl {
    unsigned int* start;
    int vdmaHandler;
    int  RS;
    int  NUM;
    int  PERIOD;
    int  lOCK_STATE;
    int  TX_ID;
    int  WK_ID;
    int  RX_ID;
    int  ADDR_T0;
    int  ADDR_T1;
    int  ADDR_T2;
    int  ADDR_T3;
    int  ADDR_R0;
    int  ADDR_R1;
    int  ADDR_R2;
    int  ADDR_R3;
    int  MREADY;
    int  SREADY;
    int  STATED;
    int  ATT;
    int  LAYER;
    int  NUMD;
    int  PIECEEND;
    int  WP;
} VideoControl;


typedef struct {
    unsigned char *fbV;
    unsigned int fbP;
} rd_addr;



typedef struct VideoBuffer {
    unsigned int* start;
    size_t  length;
} VideoBuffer;



extern VideoControl* framecontrol;

extern rd_addr readtemp[2];



extern int fd;
extern int testfd; // for read test img instead of video device
extern struct v4l2_requestbuffers reqbuf;
extern struct v4l2_buffer buf;

//extern IplImage* iplImage;
extern IplImage* iplImage_resize;
//extern IplImage* IM_show[BUFFER_COUNT];
extern cv::Mat IM_show[BUFFER_COUNT];

extern int tx_id;
extern int test_img_id;

extern vdma_handle vdma0;
extern vdma_handle vdma1;
extern vdma_handle vdma2;

extern fb_addr fbaddr0[BUFFER_COUNT];
extern fb_addr fbaddr1[BUFFER_COUNT];
extern fb_addr fbaddr2[BUFFER_COUNT];
extern fb_addr fbaddr3[BUFFER_COUNT];

extern XCvt_resize Cvt_resize;


extern VideoBuffer* framebuf;

extern QImage qqimage[BUFFER_COUNT];

int loop_id(int i);

extern int shownum_temp;

#endif // GLOBAL

